package com.itlong.cloud.property.resource;

import com.itlong.cloud.POJO.DTO.sdk.VisitorServerGetListDTO;
import com.itlong.cloud.POJO.DTO.sdk.VisitorServerSubmitDTO;
import com.itlong.cloud.POJO.VO.sdk.VisitorServerGetListVO;
import com.itlong.cloud.user.sdk.IVisitorServerServiceClient;
import com.itlong.cloud.property.service.IVisitorServerService;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      暴露操作netty通道接口Feign代理接口
 * </desc>
 *
 * @createDate 2017/12/07
 */
@RestController
public class VisitorServerServiceClientResource implements IVisitorServerServiceClient{

    @Autowired
    IVisitorServerService iVisitorServerService;

    /**
     * <desc>
     *      验证身份信息
     * <desc/>
     *
     * @param projectId
     * @return
     * @author Jiaqi.X
     * @createDate 2019/04/29
     */
    @Override
    @PostMapping(path = "/server/visitor/checkIdentity")
    public Integer checkIdentity(@RequestParam("projectId") String projectId,
                          @RequestParam("appid") String appid,
                          @RequestParam("appSecret") String appSecret){
        return iVisitorServerService.checkIdentity(projectId,appid,appSecret);
    }

    /**
     * <desc>
     *      获取地址信息
     * </desc>
     *
     * @param projectId
     * @param buildId
     * @param unitId
     * @return
     * @author Jiaqi.X
     * @createDate 2019/04/29
     */
    @Override
    @PostMapping(path = "/server/visitor/getAddressInfo")
    public List<Map<String,Object>> getAddressInfo(@RequestParam("projectId") String projectId,
                                            @RequestParam(value = "buildId",required = false) String buildId,
                                            @RequestParam(value = "unitId",required = false) String unitId){
        return iVisitorServerService.getAddressInfo(projectId,buildId,unitId);
    }

    /**
     * <desc>
     *      提交访客单
     * </desc>
     *
     * @param dto
     * @return
     * @author Jiaqi.X
     * @createDate 2019/04/29
     */
    @Override
    @PostMapping(path = "/server/visitor/submit")
    public  Map<String,Object> submit(@RequestBody VisitorServerSubmitDTO dto) throws Exception {
        return iVisitorServerService.submit(dto);
    }

    /**
     * <desc>
     *      查询访客单列表
     * </desc>
     *
     * @param dto
     * @return
     * @author Jiaqi.X
     * @createDate 2019/04/29
     */
    @Override
    @PostMapping(path = "/server/visitor/getList")
    public Page<VisitorServerGetListVO> getList(@RequestBody VisitorServerGetListDTO dto) throws Exception {
        return iVisitorServerService.getList(dto);
    }

    /**
     * <desc>
     *      审批
     * </desc>
     *
     * @param projectId
     * @param visitorNo
     * @return
     * @author Jiaqi.X
     * @createDate 2019/04/29
     */
    @Override
    @PostMapping(path = "/server/visitor/approve")
    public String approve(@RequestParam("projectId") String projectId,@RequestParam("visitorNo") String visitorNo) throws Exception{
        return iVisitorServerService.approve(projectId,visitorNo);
    }
}
